package 力扣._00周赛._424周赛.问题3;

class Solution {
    public int minZeroArray(int[] nums, int[][] queries) {
        int n = nums.length;

        int sum = 0;
        for(int num:nums)
            sum+=num;
        if(sum==0)
            return 0;

        for (int k = 0; k < queries.length; k++) {
            int l = queries[k][0];
            int r = queries[k][1];
            int val = queries[k][2];

            // nums区间[l,r]的值减去val
            for (int i = l; i <=r; i++) {
                nums[i] -= val;
            }
            // nums是否<=0
            boolean flag = true;
            for (int num:nums)
                if(num>0) {
                    flag = false;
                    break;
                }
            if(flag)
                return k+1;
        }

        return -1;
    }
}